﻿using System;
using System.Collections.Generic;
using STeaL.Functional;

namespace STeaL.Algorithm {
  public static partial class IListExtensions {
#region adjacent_find
    public static int adjacent_find<T>(this IList<T> list, int first, int last, Func<T,T,bool> pred ) {
      if ( first != last )
        for ( int firstb = first; ++first != last; ++firstb)
          if ( pred(list[firstb], list[first] ) )
            return firstb;
      return last;
    }

    public static int adjacent_find<T>(this IList<T> list, int first, int last) where T : IComparable<T> {
      return adjacent_find(list, first, last, rel_op.equal_to<T>);
    }

    public static int adjacent_find<T>(this IList<T> list, Func<T,T,bool> pred ) {
      return adjacent_find(list, 0, list.Count, pred);
    }

    public static int adjacent_find<T>(this IList<T> list) where T : IComparable<T> {
      return adjacent_find(list, 0, list.Count, rel_op.equal_to<T>);
    }

#endregion
  }
}
